package com.caine.etcd;

import com.caine.etcd.hanlder.WatchHandler;
import com.caine.etcd.tool.EtcdTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class EtcdApplication implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(EtcdApplication.class, args);
    }

    @Autowired
    EtcdTools ectdClient;

    @Override
    public void run(String... args) throws Exception {
        //有对应的key
        ectdClient.addWatch("test", new WatchHandler() {
            @Override
            public boolean put(String key, String val) {
                System.out.println(String.format(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>delete  key:%s value:%s", key, val));
                return false;
            }
            @Override
            public boolean expire(String key, String val) {
                System.out.println(String.format(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>expire  key:%s value:%s", key, val));
                return false;
            }
        });

        ectdClient.put("test", "哈哈测试一把abc123!@#", 2);
    }
}
